package com.ssy.lingxi.platform.manage.controller;

import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.model.request.shop.ShopRuleRequest;
import com.ssy.lingxi.platform.manage.entity.base.ShopRule;
import com.ssy.lingxi.platform.manage.service.IShopRuleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu 平台后台-系统管理-商城规则配置
 * @author wyx
 * @version 2.0.0
 * @date 2021-09-26
 */
@RestController
@RequestMapping("/manage/shop/rule")
public class ShopRuleController {

    @Resource
    private IShopRuleService shopRuleService;


    /**
     * 商城规则配置列表
     * @param pageVO     分页实体
     * @param memberName 会员名称
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Wrapper<PageData<ShopRule>> list(PageVO pageVO, @RequestParam(value = "memberName", required = false) String memberName) {
        return shopRuleService.list(pageVO, memberName);
    }

    /**
     * 获取商城规则配置信息
     * @param id 商城规则id
     */
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Wrapper<ShopRule> get(@RequestParam(value = "id") Long id) {
        return shopRuleService.get(id);
    }

    /**
     * 新增商城规则配置
     * @param shopRuleRequest 请求实体
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Wrapper<Void> add(@RequestBody @Validated(ShopRuleRequest.Add.class) ShopRuleRequest shopRuleRequest) {
        return shopRuleService.add(shopRuleRequest);
    }

    /**
     * 修改商城规则配置
     * @param shopRuleRequest 请求实体
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> update(@RequestBody @Validated(ShopRuleRequest.Update.class) ShopRuleRequest shopRuleRequest) {
        return shopRuleService.update(shopRuleRequest);
    }

    /**
     * 启用/停用商城规则配置
     * @param id     商城规则id
     * @param status 状态 0-无效 1-有效
     */
    @RequestMapping(value = "/updateStatus", method = RequestMethod.GET)
    public Wrapper<Void> updateStatus(@RequestParam(value = "id") Long id, @RequestParam(value = "status") Integer status) {
        return shopRuleService.updateStatus(id, status);
    }

    /**
     * 删除商城规则配置
     * @param id 商城规则id
     */
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public Wrapper<Void> delete(@RequestParam(value = "id") Long id) {
        return shopRuleService.delete(id);
    }


}
